package com.itheima.sc.service.sms;

import cn.hutool.core.convert.Convert;
import com.itheima.sc.api.sms.SmsHomeAdvertiseApi;
import com.itheima.sc.pojo.sms.HomeAdvertise;
import com.itheima.sc.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class SmsHomeAdvertiseService {

    @DubboReference
    private SmsHomeAdvertiseApi advertiseApi;

    //添加广告
    public void addAdvertise(HomeAdvertise advertise) {
        advertiseApi.addAdvertise(advertise);
    }

    //单个或批量删除广告
    public void deleteAdvertise(List<Long> ids) {
        advertiseApi.deleteAdvertise(ids);
    }

    //查询广告列表
    public PageResult selectAdvertiseList(Map<String, String> param) {
            //获取参数
            String endTime = param.get("endTime");
            String name = param.get("name");
            Integer page = Convert.toInt(param.get("pageNum"));
            Integer pageSize = Convert.toInt(param.get("pageSize"));
            Integer type = Convert.toInt(param.get("type"));
            return advertiseApi.selectAdvertiseList(page, pageSize, type, name, endTime);
    }

    //修改广告的状态
    public void updateAdvertiseStatus(Long id, Integer status) {
        HomeAdvertise advertise = new HomeAdvertise();
        advertise.setId(id);
        advertise.setStatus(status);
        advertiseApi.updateAdvertise(advertise);
    }

    //修改广告的数据
    public void updateAdvertise(Long id, HomeAdvertise advertise) {
        advertiseApi.updateAdvertise(advertise);
    }

    //查询广告详情
    public HomeAdvertise selectAdvertiseInfo(Long id) {
      return advertiseApi.selectAdvertiseById(id);
    }
}
